
LIB=libnet-dpdk.so

build_dir=${OUTDIR}/dpdk
ifeq ($(OUTDIR),)
	build_dir=./build
	LIBDIR=${build_dir}/lib
endif

SRC := $(wildcard ./*.c)
SRC_OBJ=$(SRC:.c=.o)
_SRC_OBJ=$(addprefix ${build_dir}/, $(notdir $(SRC_OBJ)))


INC=-I${SRCDIR}/inc
UDP_LIB=-L${LIBDIR} -luos-net-kit

ifeq ($(shell pkg-config --exists libdpdk && echo 0),0)

PKGCONF ?= pkg-config

PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)

#CFLAGS += -fvisibility=hidden
CFLAGS += -DALLOW_EXPERIMENTAL_API -fPIC -g
DPDK_SHARED = $(shell $(PKGCONF) --libs libdpdk)
DPDK_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)

LDFLAGS += -pthread  -Wl,-Bsymbolic

all: build_pre ${LIB}

build_pre:
	mkdir -p ${build_dir}
	mkdir -p ${LIBDIR}

${LIB}: ${_SRC_OBJ}
#	${CC} -shared ${LDFLAGS} ${CFLAGS} ${DPDK_SHARED} ${UDP_LIB} ${INC} $^ -o ${LIBDIR}/$@
	${CC} -shared ${LDFLAGS} ${CFLAGS} ${DPDK_STATIC} ${UDP_LIB} ${INC} $^ -o ${LIBDIR}/$@

${_SRC_OBJ}: ${SRC_OBJ} 

${SRC_OBJ}: %.o:%.c
	$(CC) ${CFLAGS} ${INC} -c $^ -o ${build_dir}/${notdir $@}

build:
	@mkdir -p $@

.PHONY: clean
clean:
	rm -fr build

else # Build using legacy build system
$(error "Please install libdpdk")
endif
